package com.luoxiang.socialandroid.adapter;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.luoxiang.socialandroid.R;
import com.luoxiang.socialandroid.bean.CallContent;
import com.luoxiang.socialandroid.bean.blbean;

import java.util.List;

public class GreetAdapter extends RecyclerView.Adapter<GreetAdapter.ViewHolder> {
    private List<CallContent> list;

    public GreetAdapter(List<CallContent> list) {
        this.list = list;
    }


    public static interface OnAddClickListener {
        void onItemClicks(int position, int id);
    }

    OnAddClickListener onItemAddClick;

    public void setOnAddClickListener(OnAddClickListener onItemAddClick) {
        this.onItemAddClick = onItemAddClick;
    }


    public static interface OnAddClickListenerdel {
        void onItemClicksdel(int position, int id);
    }

    OnAddClickListenerdel onItemAddClickdel;

    public void setOnAddClickListenerdel(OnAddClickListenerdel onItemAddClickdel) {
        this.onItemAddClickdel = onItemAddClickdel;
    }


    public static interface OnAddClickListenered {
        void onItemClicksed(String content, int id, String size);
    }

    OnAddClickListenered onItemAddClicked;

    public void setOnAddClickListenered(OnAddClickListenered onItemAddClicked) {
        this.onItemAddClicked = onItemAddClicked;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_greet, parent, false);
        GreetAdapter.ViewHolder holder = new GreetAdapter.ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, @SuppressLint("RecyclerView") int position) {
        CallContent bean = list.get(position);
        holder.tx_title.setText(bean.getContent());
        if (position == 0) {
            holder.tx_zhiding.setText(R.string.mi_yizhiding);
            holder.tx_zhiding.setTextColor(Color.parseColor("#835DFF"));
            holder.im_yzd.setImageResource(R.mipmap.icon_yizhiding);
        }
        holder.tx_zhiding.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onItemAddClick.onItemClicks(position, bean.getId());
            }
        });
        holder.tx_del.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onItemAddClickdel.onItemClicksdel(position, bean.getId());
            }
        });
        holder.tx_edit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String textSize = holder.tx_title.getText().length() + "";
                onItemAddClicked.onItemClicksed(bean.getContent(), bean.getId(), textSize);
            }
        });
        if (bean.getStatus() == 0) {
            holder.v_isshenhe.setVisibility(View.VISIBLE);
        } else {
            holder.v_isshenhe.setVisibility(View.GONE);
        }
    }

    @Override
    public int getItemCount() {
        try {
            return list.size();
        } catch (Exception e) {
            return 0;
        }
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private TextView tx_title, tx_zhiding, tx_del, tx_edit;
        private ImageView im_yzd, v_isshenhe;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tx_title = itemView.findViewById(R.id.tx_title);
            tx_zhiding = itemView.findViewById(R.id.tx_zhiding);
            im_yzd = itemView.findViewById(R.id.im_yzd);
            tx_del = itemView.findViewById(R.id.tx_del);
            tx_edit = itemView.findViewById(R.id.tx_edit);
            v_isshenhe = itemView.findViewById(R.id.v_isshenhe);

        }
    }
}
